{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. Python内建的数据结构、函数、文件 Built-in Data Structures, Functions, and Files\n",
    "\n",
    "This chapter discusses capabilities built into the Python language that will be used ubiquitously throughout the book."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 模块导入\n",
    "import pathlib, sys\n",
    "sys.path.append(str(pathlib.Path.cwd().parent))\n",
    "import numpy\n",
    "import pandas\n",
    "from dependency import arr_info"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.1 数据结构与序列 Data Structures and Sequences"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1.1 元组 Tuple \n",
    "\n",
    "A tuple is a fixed-length, immutable sequence of Python objects.\n",
    "\n",
    "1、元组的创建\n",
    "\n",
    "+ 用括号创建\n",
    "+ 用`tuple()`创建或将任意序列转换为元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【1】\n",
      " 类 型: <class 'tuple'>\n",
      "(1, 2, 3)\n"
     ]
    }
   ],
   "source": [
    "# 直接创建的序列默认识别为元组\n",
    "arr = 1, 2, 3   # 等价于：arr = (1, 2, 3)\n",
    "arr_info(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【1】\n",
      " 类 型: <class 'tuple'>\n",
      "((1, 2, 3), 4, 5)\n"
     ]
    }
   ],
   "source": [
    "# 用圆括号创建\n",
    "a = (1, 2, 3)\n",
    "arr = ((1, 2, 3), 4, 5)     # 多维元组一定要加上外面的括号\n",
    "arr_info(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【1】\n",
      " 类 型: <class 'tuple'>\n",
      "(1, 2, 3)\n",
      "【2】\n",
      " 类 型: <class 'tuple'>\n",
      "('h', 'e', 'l', 'l', 'o')\n",
      "e\n"
     ]
    }
   ],
   "source": [
    "# 将序列转换为元组\n",
    "a = [1, 2, 3]\n",
    "arr_1 = tuple(a)\n",
    "arr_2 = tuple(\"hello\")\n",
    "arr_info(arr_1, arr_2)\n",
    "\n",
    "print(arr_2[1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2、引用\n",
    "\n",
    "+ 用方括号索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "62962149b865b47a2b2a2c1b240717c36c0b79be90b9deaf19edb07e9fa8d98d"
  },
  "kernelspec": {
   "display_name": "Python 3.9.9 64-bit ('venv': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
